<template>
  <default-home-card icon="BarChartOutlined" title="考试总览">
    <div class="echarts-box">
      <div class="gradient-main" id="gradient-maina"></div>
    </div>

  </default-home-card>
</template>
<script setup>
  import DefaultHomeCard from '/@/views/system/home/components/default-home-card.vue';
  import * as echarts from 'echarts';
  import { onMounted, reactive } from 'vue';

  import { examromApi } from '/@/api/business/exam/examrom-api.js';

  const data = reactive({
    lista: [],
    listb: [],
    listc: [],
    listd: [],
    liste: [],
    listf: [],
  });

  const queryForm = reactive({
    docEntry: undefined, //电键
    pageNum: 1,
    pageSize: 500,
    romName: '',
  });
  onMounted(() => {
    examromApi
      .statis(queryForm)
      .then((res) => {

        data.lista = res.data.map((item) => {
          return item.romName;
        });
        data.listb = res.data.map((item) => {
          return item.openNum;
        });
        data.listc = res.data.map((item) => {
          return item.passNum;
        });
        data.listd = res.data.map((item) => {
          return item.actExamNum;
        });
        data.liste = res.data.map((item) => {
          return item.misExamNum;
        });
        data.listf = res.data.map((item) => {
          return item.correntRat;
        });
      })
      .finally(() => {
        inita();

      });
  });

  function inita() {
    let option = {

      tooltip: {
        // 是否显示提示框
        show: true,
        // 触发类型，axis 移动到坐标轴就触发
        trigger: 'axis',
      },
      legend: {
        // 图例的数据数组，
        data: ['开通人数', '通过人数', '实考人数', '缺考人数','通过率'],
      },
      xAxis: {
        type: 'category',
        data: data.lista,
      },
      yAxis: [
        {
          type: 'value',
          axisLabel: {
            formatter: '{value} ',
          },
        },
        {
          type: 'value',
          axisLabel: {
            formatter: '{value} ',
          },
        },
      ],
      series: [
        {
          name: '开通人数',
          data: data.listb,
          type: 'line',
          smooth: true,
          yAxisIndex: 0,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#ffffff',
            borderWidth: 2,
          },
          markPoint: {
            data: [
              { type: 'max', name: '最大值' },
              { type: 'min', name: '最小值' },
            ],
          },
          // 图线标注
        },
        {
          name: '通过人数',
          data: data.listc,
          type: 'line',
          smooth: true,
          yAxisIndex: 0,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#ffffff',
            borderWidth: 2,
          },
          markPoint: {
            data: [
              { type: 'max', name: '最大值' },
              { type: 'min', name: '最小值' },
            ],
          },
          // 图线标注
        },
        {
          name: '实考人数',
          data: data.listd,
          type: 'line',
          smooth: true,
          yAxisIndex: 0,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#ffffff',
            borderWidth: 2,
          },
          markPoint: {
            data: [
              { type: 'max', name: '最大值' },
              { type: 'min', name: '最小值' },
            ],
          },
          // 图线标注
        },

        {
          name: '缺考人数',
          data: data.liste,
          type: 'line',
          smooth: true,
          yAxisIndex: 0,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#ffffff',
            borderWidth: 2,
          },
          markPoint: {
            data: [
              { type: 'max', name: '最大值' },
              { type: 'min', name: '最小值' },
            ],
          },
          // 图线标注
        },
        {
          name: '通过率',
          data: data.listf,
          type: 'line',
          smooth: true,
          yAxisIndex: 1,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#ffffff',
            borderWidth: 2,
          },
          markPoint: {
            data: [
              { type: 'max', name: '最大值' },
              { type: 'min', name: '最小值' },
            ],
          },
          // 图线标注
        },
      ],
    };

    echarts.init(document.getElementById('gradient-maina')).setOption(option);
  }


</script>
<style lang="less" scoped>
  .echarts-box {
    display: flex;
    align-items: center;
    justify-content: center;

    .gradient-main {
      width: 2000px;
      height: 400px;
      background: #fff;
    }
  }
</style>
